package com.xscha.soyue.common.core.utils;

import com.xscha.soyue.common.core.exception.status.SoyStatusCode;
import org.springframework.http.HttpStatus;

import java.util.Objects;
import java.util.regex.Pattern;

/**
 * http状态码工具类
 *
 * @author Vondser
 * @version V2024.1.0
 */
public class StatusCodeUtils {

	private static final Pattern NUMBER_PATTERN = Pattern.compile("[0-9]+");

	public static Integer getActiveHttpCode(SoyStatusCode status) {
		if (Objects.isNull(status)) {
			return null;
		}
		if (NUMBER_PATTERN.matcher(status.getCode().toString()).matches()) {
			HttpStatus resolve = HttpStatus.resolve(status.getCode());
			if (Objects.nonNull(resolve)) {
				return resolve.value();
			}
		}
		return null;
	}

}
